import { onMounted, onUnmounted, Ref, ref } from 'vue';
const clickOutside = (element: Ref<HTMLElement | null>) =>{
  let isClick = ref(false)
  // 点击事件回调函数
  const handler = (e: MouseEvent)=>{
    // 判断有没有这个节点
    if (element.value) {
      // 判断点击节点是不是这个节点的子节点
      if (element.value.contains(e.target as HTMLElement)) {
        isClick.value = false
      }else{
        isClick.value = true
      }
    }
  }
  onMounted(() => {
    document.addEventListener('click', handler)
  })
  onUnmounted(() => {
    document.removeEventListener('click', handler)
  })
  return isClick
}
export default clickOutside